/**
 * 
 * JShakki  - Dude with recycled paper.
 * 
 * @version 1.0
 * 
 * Copyright (C) 2006 Jarkko Sipilä
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 * 
 * 
 */

package dude.data;

import java.awt.Dimension;

public class Board {
  
  Square[][] squares;
  
  private boolean turn = true;
  private Dude dude;
  private int boardSize;

  public static final int DEFAULT_SIZE = 20;
  public static final int MINIMUM_SIZE = 5;
  public static final int MAXIMUM_SIZE = 100;
  
  protected Board( int boardSize, Dude creator ) {
    
    this.boardSize = boardSize;
    this.dude = creator;
    this.squares = new Square[boardSize][boardSize];
    
    for ( int y = 0; y < boardSize; y++ )
      for ( int x = 0; x < boardSize; x++ )
        this.squares[x][y] = new Square( new Dimension(x, y), this );
  }
 
  protected boolean isXTurn() {
    return this.turn;
  }
   
  protected void changeTurn() {
    this.turn = !this.turn;
  }

  protected void dataSetOwner( Dimension d ) {
    if( d.width < 0 || d.width >= this.boardSize ||
        d.height < 0  || d.height >= this.boardSize ) {
      // do nothing
    }
    else
      this.squares[d.width][d.height].setOwner();
  }
  
  protected Square getSquare( Dimension d ) {
    if( d.width >= 0 && d.width < this.boardSize )
      if ( d.height >= 0 && d.height < this.boardSize )
        return this.squares[d.width][d.height];
    
    return null;
  }
  
  protected void guiDrawLine( Dimension d, int direction ) {
    this.dude.guiDrawLine( d, direction ); 
  }
  
  protected void guiDrawOwner( Dimension d, char c ) {
    this.dude.guiDrawOwner( d, c );		
  }
}
